<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">  

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<!DOCTYPE html>
<html>
<head>
<title>自动凭证模板</title>
</head>
<body>	
	<script type="text/javascript">
		var dataGrid;
		$(function() {
			dataGrid = $('#pzmbdataGrid').datagrid({
				url : '${pageContext.request.contextPath}/business/accounting/zdpzmb/dataGrid.shtml',
				fit : true,
				border : false,
				pagination : true,
				idField : 'id',
				pageSize : 20,
				pageList : [ 10, 20, 30, 40, 50 ],
				sortName : 'ID',
				sortOrder : 'ASC',
				checkOnSelect : false,
				selectOnCheck : false,
				nowrap : false,
				striped : true,
				rownumbers : true,
				singleSelect : true,
				columns : [ [{
					field : 'ID',
					title : '编号',
					width : 150,
					hidden : true
				},{
					field : 'action',
					title : '操作',
					width : 150,
					formatter : function(value, row, index) {
						var str = '';
						str += $.formatString('<a onclick="editFun(\'{0}\');"><button>编辑</button></a>', row.ID);
						str += '&nbsp;';
						str += $.formatString('<a onclick="deleteFun(\'{0}\');"><button>删除</button></a>', row.ID);
						str += '&nbsp;';
						return str;
					}
				},{
					field : 'HSDW',
					title : '核算单位',
					width : 200,
					sortable : true
				}, {
					field : 'ZTMC',
					title : '账套名称',
					width : 200,
					sortable : true
				}, {
					field : 'MBLX',
					title : '模版类型',
					width : 200,
					sortable : true
				}, {
					field : 'MBBH',
					title : '模版编号',
					width : 200,
					sortable : true
				}, {
					field : 'MBMC',
					title : '模版名称',
					width : 200,
					sortable : true
				}
				
				]],
				toolbar : '#pzmptoolbar',
				onLoadSuccess : function() {
					$('#searchForm table').show();
					parent.$.messager.progress('close');
					$(this).datagrid('tooltip');
				},
				onRowContextMenu : function(e, rowIndex, rowData) {
					e.preventDefault();
					$(this).datagrid('unselectAll');
					$(this).datagrid('selectRow', rowIndex);
					$('#pzmbmenu').menu('show', {
						left : e.pageX,
						top : e.pageY
					});
				}
			
			});
			console.info(dataGrid);
		});
	
		function deleteFun(id) {
			if (id == undefined) {
				var rows = dataGrid.datagrid('getSelections');
				id = rows[0].ID;
			}
			parent.$.messager.confirm('询问', '您是否要删除当前选择数据？', function(b) {
				if (b) {
					parent.$.messager.progress({
						title : '提示',
						text : '数据处理中，请稍后....'
					});
					$.post('${pageContext.request.contextPath}/business/accounting/zdpzmb/delete.shtml', {
						id : id
					}, function(result) {
						if (result.success) {
							parent.$.messager.alert('提示', result.msg, 'info');
							dataGrid.datagrid('reload');
						}
						parent.$.messager.progress('close');
					}, 'JSON');
				}
			});
		}
	
		function editFun(id) {
			if (id == undefined) {
				var rows = dataGrid.datagrid('getSelections');
				id = rows[0].ID;
			}
			parent.$.modalDialog({
				title : '凭证分录',
				width : 1000,
				height : 600,
				href : '${pageContext.request.contextPath}/business/accounting/zdpzmb/editPage.shtml?id=' + id,
				
			});
		}
	
		function addFun() {
			parent.$.modalDialog({
				title : '添加科科目',
				width : 780,
				height : 500,
				href : '${pageContext.request.contextPath}/business/accounting/zdpzmb/addPage.shtml',
				buttons : [ {
					text : '添加',
					handler : function() {
						parent.$.modalDialog.openner_dataGrid = dataGrid;//因为添加成功之后，需要刷新这个dataGrid，所以先预定义好
						var f = parent.$.modalDialog.handler.find('#form');
						f.submit();
					}
				} ]
			});
		}
	
		function searchFun() {
			dataGrid.datagrid('reload', $.serializeObject($('#searchForm')));
		}
		function cleanFun() {
			$('#searchForm input').val('');
			dataGrid.datagrid('load', {});
		}
	</script>
	<div class="easyui-layout" data-options="fit : true,border : false">
		<div data-options="region:'north',title:'',border:false" style="height: 100px; overflow: hidden;" >
			<form id="searchForm">
				<table class="form_view_border" bordercolordark="#FFFFFF" bordercolorlight="#45b97c" border="px" cellpadding="0" cellspacing="0" style="">
					<tr>
						<th class="panel-header"><nobr>核算单位</nobr></th>
						<td>
							<input style="width: 156px;height: 27px;" class="easyui-text"
							name="HSDW_CONTAINS_STR" 
							class="span2" />
						</td>
						<th class="panel-header"><nobr>帐套名称</nobr></th>
						<td>
							<input style="width: 156px;height: 27px;" class="easyui-text"
							name="ZTMC_CONTAINS_STR" 
							class="span2" />
						</td>
						<th class="panel-header"><nobr>模版类型</nobr></th>
						<td>
							<input style="width: 156px;height: 27px;" class="easyui-text"
							name="MBLX_EQ_STR" 
							class="span2" />
						</td>
						<th class="panel-header"><nobr>模版编码</nobr></th>
						<td>
							<input style="width: 156px;height: 27px;" class="easyui-text"
							name="MBBH_CONTAINS_STR" 
							class="span2" />
						</td>
					</tr>
				</table>
			</form>
		</div>
		<div data-options="region:'center',border:false">
			<table id="pzmbdataGrid"></table>
		</div>
	</div>
	<div id="pzmptoolbar" >
			<a onclick="addFun();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'add'">增加</a>
		    <a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'brick_add',plain:true" onclick="searchFun();">查询</a>
		    <a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'brick_delete',plain:true" onclick="cleanFun();">重置</a>
		
	
	</div>
	<div id="pzmbmenu" class="easyui-menu" style="width: 120px;display:none; ">
			<div onclick="addFun();" data-options="iconCls:'pencil_add'">增加</div>
			<div onclick="deleteFun();" data-options="iconCls:'pencil_delete'">删除</div>
			<div onclick="editFun();" data-options="iconCls:'pencil'">编辑</div>
	</div> 
</body>
</html>